#ifndef SOURCEROW_H
#define SOURCEROW_H

#include <QObject>

#include "source.h"

#include <QList>
#include <QIcon>

class QStandardItem;

class ItemRow;
class StandardItemIconAnimator;
class FavIconGrabber;

class SourceRow : public QObject
{
    Q_OBJECT

public:
    SourceRow(
        Source *source
    ,   ItemRow *parent);
    virtual ~SourceRow();

    Source *source() const;
    ItemRow *parent() const;


    QList<QStandardItem*> items() const;
    QStandardItem *firstColumnItem() const;

    const int row() const;


    void itemChanged(QStandardItem *item);
    const bool hasItemInRow(QStandardItem *item) const;

signals:
    void columnWidthChanged(int column);
    void multipleColumnWidthsChanged();

protected:
    static const QString toPriceString(const int price);

    void createItems();
    void createIconAnimator();

    void setToolTip(const QString &tooltip);
    void setIcon(const QIcon &icon);

    void setEnabled(const bool enabled);

    void checked_changed();
    void name_dataChanged();
    void price_dataChanged();
    void quantity_dataChanged();
    void url_dataChanged();

    void grabFavIcon();

protected slots:
    void source_ignoreStateChanged(bool ignore);

    void source_nameChanged(const QString &name);
    void source_priceChanged(int price);
    void source_quantityChanged(uint quantity);
    void source_urlChanged(const QUrl &url);

    void source_updateStarted();
    void source_updated(bool succeeded);
    void source_canceled();

    void favIconGrabber_finished(QIcon &icon);

protected:
    Source *m_source;
    ItemRow *m_parent;

    QIcon m_icon;

    QStandardItem *m_nameItem;
    QStandardItem *m_priceItem;
    QStandardItem *m_quantityItem;
    QStandardItem *m_urlItem;

    FavIconGrabber *m_favIconGrabber;
    StandardItemIconAnimator *m_itemIconAnimator;
};

#endif // SOURCEROW_H
